package com.jcy_lyh.enjoy_all;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

import static java.lang.System.in;

public class Second3Activity extends Activity {
    private EditText period;
    private int value;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_second3);
        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(
                MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }

        public void setAlarm(View view) {
            period = (EditText)findViewById(R.id.editText16);
            value = Integer.parseInt(period.getText().toString());
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.HOUR, value);
            Date hoursLater = calendar.getTime();
            Toast.makeText(this, "The alarm will set off at " +
                    hoursLater, Toast.LENGTH_LONG).show();
            AlarmManager alarmMgr = (AlarmManager) getSystemService(
                    Context.ALARM_SERVICE);
            Intent intent = new Intent(this, WakeUpActivity.class);
            PendingIntent sender = PendingIntent.getActivity(
                    this, 0, intent, 0);
            alarmMgr.set(AlarmManager.RTC_WAKEUP,
                    hoursLater.getTime(), sender);
        }
    }

